﻿using AutoMapper;
using Data0426.Base.Common;
using Data0426.Base.Dommain;
using Data0426.Base.Infrastructure;
using Data0426.Base.Read.API.Applaction.Command;
using Data0426.Base.Write.API.Applaction.Command;
using MediatR;
using System.Security.Cryptography;

namespace Data0426.Base.Write.API.Applaction.Hander
{
    public class CreateLoginHander : IRequestHandler<CreateFormTypeCommand, ApiResult<int>>
    {
        private readonly IBaseRequest<FormType> FormTypeRequert;
        private readonly IMapper mapper;

        public CreateLoginHander(IBaseRequest<FormType> formTypeRequert, IMapper mapper)
        {
            FormTypeRequert = formTypeRequert;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(CreateFormTypeCommand request, CancellationToken cancellationToken)
        {
            var result=new ApiResult<int>();
            var entity = mapper.Map<FormType>(request);
            var info = FormTypeRequert.Create(entity);
            if(info>0)
            {
                result.data = info;
                result.code = ApiEnumcode.OK;
                result.meg = "添加成功";
                return Task.FromResult(result);
            }
            else
            {
                result.data = info;
                result.code = ApiEnumcode.Faile;
                result.meg = "失败";
                return Task.FromResult(result);
            }
        }
    }
}
